﻿using Newtonsoft.Json;
using System.ComponentModel;

namespace ReNameEx.Model
{
    public abstract class ReExRuleBase : INotifyPropertyChanged
    {
        public ReExRuleBase()
        {
            TypeName = this.GetType().FullName ?? "";
        }
        /// <summary>
        /// 类型名称
        /// </summary>
        public string TypeName { get; set; }
        /// <summary>
        /// 是否启用
        /// </summary>
        private bool _Enable = true;
        public virtual bool Enable
        {
            get { return _Enable; }
            set { _Enable = value; OnPropertyChanged("Enable"); }
        }

        /// <summary>
        /// 排序
        /// </summary>
        private int _Order;
        public virtual int Order
        {
            get { return _Order; }
            set { _Order = value; OnPropertyChanged("Order"); }
        }

        /// <summary>
        /// 忽略大小写
        /// </summary>
        private bool _IgnoreCase = true;
        public virtual bool IgnoreCase
        {
            get { return _IgnoreCase; }
            set { _IgnoreCase = value; OnPropertyChanged("IgnoreCase"); }
        }

        /// <summary>
        /// 忽略扩展名
        /// </summary>
        private bool _IgnoreExtension = true;
        public virtual bool IgnoreExtension
        {
            get { return _IgnoreExtension; }
            set { _IgnoreExtension = value; OnPropertyChanged("IgnoreExtension"); }
        }

        /// <summary>
        /// 反转顺序（从右到左）
        /// </summary>
        private bool _ReverseOrder = true;
        public virtual bool ReverseOrder
        {
            get { return _ReverseOrder; }
            set { _ReverseOrder = value; OnPropertyChanged("ReverseOrder"); }
        }

        /// <summary>
        /// 描述
        /// </summary>
        [JsonIgnore]
        public virtual string Desc { get { return GetDesc(); } }

        public abstract string GetDesc();

        public abstract void PrewRule(IEnumerable<ReExFile> files);
        //public override void PrewRule(IEnumerable<ReExFile> files)
        //{
        //    if (Enable)
        //    {
        //        foreach (ReExFile file in files)
        //        {
        //            if (file.IsApply)
        //            {
        //                file.NewFileName = file.NewFileName.Replace("psd", "clip");
        //            }
        //        }
        //    }
        //}

        public event PropertyChangedEventHandler? PropertyChanged;

        protected virtual void OnPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}
